package com.work.formaldehyde.activityadapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.work.formaldehyde.R;
import com.work.formaldehyde.activity.ShangPingActivity;
import com.work.formaldehyde.model.ShangPingXiangQingModel;
import com.work.formaldehyde.view.RoundImageView;

import java.util.ArrayList;

public class CommentAdapter extends BaseAdapter {
    ArrayList<String> list;
    ArrayList<ShangPingXiangQingModel.comment> lists;
    Context context;

    public CommentAdapter(ArrayList<String> list, ArrayList<ShangPingXiangQingModel.comment> lists, Context context) {
        // TODO Auto-generated constructor stub
        this.list = list;
        this.lists = lists;
        this.context = context;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return lists != null ? lists.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return lists != null ? lists.get(position) : 0;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        convertView = LayoutInflater.from(context).inflate(R.layout.comment_list_item, null);
        init i = new init();
        i.username = convertView.findViewById(R.id.username);
        i.com_time = convertView.findViewById(R.id.com_time);
        i.user_comment = convertView.findViewById(R.id.user_comment);
        i.user_like = convertView.findViewById(R.id.user_like);
        i.ilk_text = convertView.findViewById(R.id.ilk_text);
        i.comment_item_headimg = convertView.findViewById(R.id.comment_item_headimg);
        i.ilk = convertView.findViewById(R.id.ilk);
//        if (list.get(position).equals("0")) {
//            i.ilk_text.setText("取消");
//            i.ilk_text.setTextColor(context.getResources().getColor(R.color.home_bottom_text_color_ischeck));
//            i.ilk.setBackgroundDrawable(context.getResources().getDrawable(R.mipmap.ilks));
//        } else {
//            i.ilk_text.setText("点赞");
//            i.ilk_text.setTextColor(context.getResources().getColor(R.color.text_black60));
//            i.ilk.setBackgroundDrawable(context.getResources().getDrawable(R.mipmap.ilk));
//        }
        i.username.setText(lists.get(position).getUser_name());
        i.com_time.setText(lists.get(position).getTimes());
        i.user_comment.setText(lists.get(position).getContent());
        Glide.with(context)
                .load(lists.get(position).getUser_head())
                .into(i.comment_item_headimg);
        convertView.setTag(i);
        return convertView;
    }

    public static class init {
        //首页list的子控件
        TextView username, com_time, user_comment, ilk_text;
        ImageView ilk;
        LinearLayout  user_like;
        RoundImageView comment_item_headimg;
    }
}

